<template>
  <div>
    <el-table v-loading.body="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="id" label="id" min-width="40" align="center" ></el-table-column>
      <el-table-column prop="user_name" label="账号" min-width="80" align="center" ></el-table-column>
      <el-table-column prop="create_time" label="创建时间" min-width="80" align="center" ></el-table-column>
      <el-table-column class-name="status-col" label="状态" min-width="80">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.is_del |statusName()}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作"  min-width="80">
        <template slot-scope="scope">
          <router-link :to="'/guest/guestdetail?id='+scope.row.id">
            <el-button type="text" size="small" icon="el-icon-edit">详情</el-button>
          </router-link>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.limit"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>
import {userDetail, userList} from "../../api/user";

export default {
  name: "list",
  filters: {
    statusName(is_del) {
      if (is_del===0) {
        return '正常';
      }else{
        return '已删除'
      }
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        group_id: 1,
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      userList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.count
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.listQuery.page = 1
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    deleteAdmin(id){
      this.$confirm('此操作将永久删除该账号, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        adminDelete({"ids":id}).then(response => {
          //console.log(response.data)
          this.listLoading = false
        })

        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        this.$router.push({
          'path':'/admin/adminlist',
          query: {
            t: +new Date() // 保证每次点击路由的query项都是不一样的，确保会重新刷新view
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


    }

  }
}
</script>

<style scoped>

</style>
